package com.kfm.base.map;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Demo04 {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();

        list.add("张无忌");
        list.add("周芷若");
        list.add("赵敏");
        list.add("阳顶天");
        list.add("小昭");
        list.add("杨逍");
        list.add("杨过");
        list.add("韦一笑");
        list.add("谢逊");
        list.add("灭绝师太");
        list.add("静虚师太");


        // Stream 操作集合
        Stream<String> stream = list.stream();

        // 过滤 filter， 表达式返回 true 表示保留
        Stream<String> lengthStream = stream.filter(e -> e.length() >= 3);

        // 再次过滤
        Stream<String> result = lengthStream.filter(e -> !e.contains("师太"));

        // 遍历
        result.forEach(e -> System.out.println(e));

        // 优化
        list.stream()
                .filter(e -> e.length() >= 3)
                .filter(e -> !e.contains("师太"))
                .forEach(e -> System.out.println(e));

        System.out.println(list);


        int[] arr = new int[]{3, 5, 1, 9, 6, 250};

        // 获取数组的 stream 流
        IntStream stream1 = Arrays.stream(arr);

        stream1.filter( e -> e > 5)
                .skip(2)
                .forEach( e -> System.out.println(e));


        Stream<String> stream2 = Stream.of("a", "b");

    }
}
